import nuxtStorage from 'nuxt-storage'
export const state = () => ({
  userInfo: {}
});

export const mutations = {
  setUserInfo(state, data) {
    nuxtStorage.localStorage.setData('userInfo', data)
    state.userInfo = data;
  },
  removeUserInfo(state) {
    nuxtStorage.localStorage.removeItem('userInfo')
    state.userInfo = {};
  }
};

export const actions = {
  async getUserInfo({ commit }) {
    return this.$api.userInfo().then(res => {
      if (res.code == 200) {
        commit('setUserInfo', res.data)
      }
    })
  }
};

export const getters = {
  userInfo: state => state.userInfo
};
